package com.situ.struts.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class DataAction1 extends ActionSupport {

    @Override
    public String execute() throws Exception {
        System.out.println("DataAction1 execute().");
        // 方式一：直接获得Servlet的API，使用核心类ServletActionContext提供的静态方法
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        ServletContext servletContext = ServletActionContext.getServletContext();
        request.setAttribute("request_data1", "request_data11");
        session.setAttribute("session_data1", "session_data11");
        servletContext.setAttribute("application_data1", "application_data11");

        return SUCCESS;
    }
}
